package org.qpcr.community.project.web;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.ezorm.core.param.Term;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.QueryAction;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
import org.qpcr.community.project.model.entity.SoftwareVersionEntity;
import org.qpcr.community.project.service.SoftwareVersionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping( {"/SoftwareVersion"})
@Authorize
@Resource(id = "Software-Version", name = "软件版本管理")
@Slf4j
@Tag(name = "软件版本接口")
@RequiredArgsConstructor
public class SoftwareVersionController implements ReactiveServiceCrudController<SoftwareVersionEntity, String> {
    @Getter
    private final SoftwareVersionService service;

    @GetMapping("/querNewData/{type}")
    @QueryAction
    @Operation(
        summary = "查询最新的版本数据"
    )
    @Authorize(ignore = true)
    public  Flux<SoftwareVersionEntity>  querNewData(@RequestBody Flux<SoftwareVersionEntity> payload,@PathVariable Integer type) {
        QueryParamEntity param=new QueryParamEntity();
        List<Term> list =new ArrayList<>();
        Term term=new Term();
        term.setColumn("type");
        term.setValue(type);
        list.add(term);
        param.setTerms(list);

        param.setOrderBy("createTime desc");
        param.setPageSize(1);

        return this.service.query(param);
    }


}
